//
//  UIImage+Clicp.m
//  OffScreenDemo
//
//  Created by 梁立保 on 2019/6/13.
//  Copyright © 2019 梁立保. All rights reserved.
//

#import "UIImage+Clicp.h"

@implementation UIImage (Clicp)
//绘制图片圆角
- (UIImage *)drawCornerInRect:(CGRect)rect
                 cornerRadius:(CGFloat)cornerRadius {
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect
                                                          cornerRadius:cornerRadius];
    UIGraphicsBeginImageContextWithOptions(rect.size, false, [UIScreen mainScreen].scale);
    CGContextAddPath(UIGraphicsGetCurrentContext(), bezierPath.CGPath);
    CGContextClip(UIGraphicsGetCurrentContext());
    [self drawInRect:rect];
    
    CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathFillStroke);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
@end
